<?php
/**
 * Author: Traveler
 * Time  : 2021/8/31 16:34
 */

use app\middleware\Auth;
use think\facade\Route;

/**
 * crm相关路由
 */
Route::group("crm/<ver>", function () {
    /**
     * 不需要验证token的路由
     */
    Route::group('login', function () {
        // 账号登陆
        Route::post('account', 'Login/account');
    });

    /**
     * 需要验证token的组
     */
    Route::group(function () {
        // 登陆后相关(登陆后用户信息、菜单权限、统计信息等)
        Route::group('main', function () {
            Route::get('profile', 'Main/getProfile');
            Route::put('password', 'Main/changePassword');
            Route::get('statistics/company', 'Main/getCompanyStatistics');
            Route::get('statistics/icafe', 'Main/getIcafeStatistics');
        });

        // 场所相关
        Route::group('icafe', function () {
            Route::resource('', 'Icafe');
            Route::resource('category', 'IcafeCategory');
            Route::resource('wan', 'IcafeWan');
            Route::resource('adsl', 'IcafeAdsl');
            Route::get('<id>/tech', 'Icafe/getTechData');
            Route::get('mirror', 'IcafeMirror/get');
            Route::put('mirror', 'IcafeMirror/save');
            Route::get('cnk', 'IcafeCnk/get');
            Route::put('cnk', 'IcafeCnk/save');
        });

        // 运营商相关
        Route::resource('isp', 'Isp');

        // 用户相关
        Route::resource('user', 'User');

        // 员工相关
        Route::resource('staff', 'Staff');

        // 角色相关
        Route::group('role', function () {
            Route::resource('', 'Role');
            // 分配权限
            Route::put('<id>/assign', 'Role/assignPermission');
        });

        // 部门相关
        Route::resource('department', 'Department');

        // 菜单相关
        Route::resource('menu', 'Menu');

        // 行政区域相关
        Route::resource('region', 'Region');

    })->middleware(Auth::class);
})->prefix('crm.<ver>.')->pattern(['id' => '\d+'])->allowCrossDomain();
